{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from asyncio.windows_events import NULL\n",
    "import json\n",
    "from xml.dom.minidom import parse\n",
    "import xml.dom.minidom\n",
    "from enum import Enum\n",
    "import zipfile\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import warnings\n",
    "import zipfile, os\n",
    "warnings.filterwarnings('ignore')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "mode_2V2 = [33, 59, 62]\n",
    "add_1_horse = []\n",
    "#-1马的id\n",
    "reduce_1_horse = []\n",
    "#装备id\n",
    "equips_list = []\n",
    "#武器id\n",
    "armss_list = []\n",
    "#闪电标记\n",
    "flash_list = []\n",
    "#乐不思蜀\n",
    "lbss_list = []\n",
    "#兵粮寸断状态\n",
    "blcd_list = []\n",
    "#酒的状态\n",
    "jiu_list = []\n",
    "#铁索连环\n",
    "tslh_list = []"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "#保存数据到csv\n",
    "def save2csv(filename, idata):\n",
    "    file_out = open(\"save_data./\"+filename, 'a+', encoding='UTF-8')  # create file\n",
    "    file_out.write(idata+\"\\n\")\n",
    "    file_out.close()\n",
    "\n",
    "#字符串联\n",
    "def contanctStr(basestr, addstr):\n",
    "    basestr = basestr + \",\"+str(addstr)\n",
    "    return basestr\n",
    "\n",
    "#保存手牌\n",
    "def ansyiceHandcards(_str, _deflist):\n",
    "    _defstr = ''\n",
    "    if _deflist == None or len(_deflist) == 0:\n",
    "        return _str\n",
    "    for value in _deflist:\n",
    "        _defstr = _defstr + str(value) + '|'\n",
    "    _str = contanctStr(_str, _defstr)\n",
    "    return _str\n",
    "\n",
    "    \n",
    "#是否有乐不思蜀\n",
    "def judge_have_lbss(cards):\n",
    "    for card in cards:\n",
    "        if card in lbss_list:\n",
    "            return 1\n",
    "    return 0\n",
    "\n",
    "#是否有闪电\n",
    "def judge_have_flash(cards):\n",
    "    for card in cards:\n",
    "        if card in flash_list:\n",
    "            return 1\n",
    "    return 0\n",
    "    \n",
    "#是否有兵粮寸断\n",
    "def judge_have_blcd(cards):\n",
    "    for card in cards:\n",
    "        if card in blcd_list:\n",
    "            return 1\n",
    "    return 0\n",
    "\n",
    "#是否是铁索连环\n",
    "def judge_have_tslh(cards):\n",
    "    for card in cards:\n",
    "        if card in tslh_list:\n",
    "            return 1\n",
    "    return 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[130,\n",
       " 137,\n",
       " 143,\n",
       " 150,\n",
       " 156,\n",
       " 1018,\n",
       " 1072,\n",
       " 1098,\n",
       " 4124,\n",
       " 4130,\n",
       " 4136,\n",
       " 4143,\n",
       " 4149,\n",
       " 6088,\n",
       " 6104,\n",
       " 130,\n",
       " 137,\n",
       " 143,\n",
       " 150,\n",
       " 156,\n",
       " 1018,\n",
       " 1072,\n",
       " 1098,\n",
       " 4124,\n",
       " 4130,\n",
       " 4136,\n",
       " 4143,\n",
       " 4149,\n",
       " 6088,\n",
       " 6104]"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "jiu_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [],
   "source": [
    "#从playcards里面提取+1马，-1马，装备牌，武器牌的id\n",
    "DOMTree_card = xml.dom.minidom.parse(\"playcard.xml\")\n",
    "collection_card = DOMTree_card.documentElement\n",
    "\n",
    "# 在集合中获取 所有spell\n",
    "cards = collection_card.getElementsByTagName(\"card\")\n",
    "for item in cards:\n",
    "    if item.getAttribute(\"type\") == \"3\":\n",
    "        #武器\n",
    "        if item.getAttribute(\"subType\") == \"1\":\n",
    "            armss_list.append(int(item.getAttribute(\"id\")))\n",
    "        #护甲\n",
    "        elif item.getAttribute(\"subType\") == \"2\":\n",
    "            equips_list.append(int(item.getAttribute(\"id\")))\n",
    "        #+1马\n",
    "        elif item.getAttribute(\"subType\") == \"3\":\n",
    "            add_1_horse.append(int(item.getAttribute(\"id\")))\n",
    "        #-1马\n",
    "        elif item.getAttribute(\"subType\") == \"4\":\n",
    "            reduce_1_horse.append(int(item.getAttribute(\"id\")))\n",
    "    elif item.getAttribute(\"name\") == \"闪电\":\n",
    "        flash_list.append(int(item.getAttribute(\"id\")))\n",
    "    elif item.getAttribute(\"name\") == \"乐不思蜀\":\n",
    "        lbss_list.append(int(item.getAttribute(\"id\")))\n",
    "    elif item.getAttribute(\"name\") == \"兵粮寸断\":\n",
    "        blcd_list.append(int(item.getAttribute(\"id\")))\n",
    "    elif item.getAttribute(\"name\") == \"铁索连环\":\n",
    "        tslh_list.append(int(item.getAttribute(\"id\")))\n",
    "    elif item.getAttribute(\"name\") == \"酒\":\n",
    "        jiu_list.append(int(item.getAttribute(\"id\")))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "class role_figure(Enum):\n",
    "    FIGURE_INVALID      = 0, #无效类型\n",
    "    FIGURE_EMPEROR      = 1, #主公,   1v1的后手\n",
    "    FIGURE_MINISTER     = 2, #忠臣 \n",
    "    FIGURE_REBEL        = 3, #反贼\n",
    "    FIGURE_PROVOCATEUR  = 4, #内奸"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "max_seat_id = 7\n",
    "my_seatid = 255\n",
    "table_players = {}\n",
    "table_game_mode = -1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Spell():\n",
    "   id = 0\n",
    "   name=\"\"\n",
    "   type=0\n",
    "   type_desc=\"\"\n",
    "   gameautoAITarget = 0\n",
    "   Zhanqi_Range = 0\n",
    "\n",
    "class Card():\n",
    "   id = 0\n",
    "   name = \"\"\n",
    "   type = 0\n",
    "   subType = 0\n",
    "   color = 0\n",
    "   number = 0\n",
    "   attRange = 0\n",
    "   ZhanqiRange = 0\n",
    "   attDistance = 0\n",
    "   defDistance = 0\n",
    "   spellId = 0\n",
    "   cardsGroup = \"\"\n",
    "\n",
    "class Character():\n",
    "   id = 0\n",
    "   name = \"\"\n",
    "   exType = 0\n",
    "   country = 0\n",
    "   color = 0\n",
    "   gender = 0\n",
    "   hp = 0\n",
    "   spellId1 = 0\n",
    "   spellId2 = 0\n",
    "   spellId3 = 0\n",
    "   spellId4 = 0\n",
    "   spellId5 = 0\n",
    "   spellIds =[]\n",
    "\n",
    "class Player():\n",
    "   seat_id = -1\n",
    "   role_id = -1\n",
    "   country = -1\n",
    "   character_id = -1 #武将id\n",
    "   my_name = \"\"\n",
    "   my_char = NULL\n",
    "   figure = role_figure.FIGURE_INVALID\n",
    "   use_spell = []\n",
    "   hand_cards = [] #手牌\n",
    "   hand_cards_count = 0\n",
    "   add_horse = -1 #+1马\n",
    "   reduce_horse = -1 #-1马\n",
    "   equips = -1 #武器\n",
    "   arms  = -1 #护甲\n",
    "   zb_cards = [] #装备卡牌\n",
    "   giveup_cards = [] #弃牌牌堆\n",
    "   out_cards = [] #出牌牌堆\n",
    "   decide_cards =[] #判定区\n",
    "   init_hp = 0\n",
    "   max_hp = 0 #最大血量\n",
    "   result = 0 #游戏结果\n",
    "\n",
    "   def __init__(self, seat_id, role_id, country):\n",
    "      self.seat_id = seat_id\n",
    "      self.role_id = role_id\n",
    "      self.country = country\n",
    "      self.my_char = Character()\n",
    "      print(\"init player\")\n",
    "      return\n",
    "\n",
    "   def update_char_info(self, character):\n",
    "      self.my_char.id = character.id\n",
    "      self.my_char.name = character.name\n",
    "      self.my_char.exType = character.exType\n",
    "      self.my_char.country = character.country\n",
    "      self.my_char.color = character.color\n",
    "      self.my_char.gender = character.gender\n",
    "      self.my_char.hp = character.hp\n",
    "      self.my_char.spellIds = []\n",
    "      self.my_char.spellId1 = character.spellId1\n",
    "      self.my_char.spellId2 = character.spellId2\n",
    "      self.my_char.spellId3 = character.spellId3\n",
    "      self.my_char.spellId4 = character.spellId4\n",
    "      self.my_char.spellId5 = character.spellId5\n",
    "      self.my_char.spellIds = character.spellIds\n",
    "      self.my_name = self.my_char.name\n",
    "      return\n",
    "\n",
    "   def reset(self):\n",
    "      seat_id = -1\n",
    "      char_id = -1\n",
    "      country = -1\n",
    "      character_id = -1 #武将id\n",
    "      my_name = \"\"\n",
    "      my_char = NULL\n",
    "      figure = role_figure.FIGURE_INVALID\n",
    "      use_spell = []\n",
    "      hand_cards = [] #手牌\n",
    "      add_horse = -1 #+1马\n",
    "      reduce_horse = -1 #-1马\n",
    "      equips = -1 #武器\n",
    "      arms  = -1 #护甲\n",
    "      zb_cards = [] #装备卡牌\n",
    "      giveup_cards = [] #弃牌牌堆\n",
    "      out_cards = [] #出牌牌堆\n",
    "      decide_cards = [] #判定区\n",
    "\n",
    "   def update_spell_info(self, spell):\n",
    "      self.use_spell.append(spell)\n",
    "\n",
    "   def update_opt_info(self, opt):\n",
    "      print(self.my_name, \"do opt: \", opt)\n",
    "\n",
    "   def update_char_data(self, character):\n",
    "      return\n",
    "\n",
    "def check_int(value, revalue=0):\n",
    "   if value is NULL:\n",
    "      return revalue\n",
    "   if value == \"\" or value == '':\n",
    "      return revalue\n",
    "   return int(value)\n",
    "\n",
    "def get_table_player(seat_id):\n",
    "   for _player in table_players:\n",
    "      if _player.seat_id == seat_id:\n",
    "         return _player\n",
    "\n",
    "def reset_player_info():\n",
    "   global table_players \n",
    "   table_players = {}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "#桌子信息\n",
    "table_players = {}\n",
    "def func_userseat_ntf(msg):\n",
    "   global talbe_player_count\n",
    "   global table_game_mode\n",
    "   my_seatid = msg[\"my_seatid\"]\n",
    "   table_game_mode = msg[\"model\"]\n",
    "   seat_list = []\n",
    "   role_list = []\n",
    "   if len(msg[\"seatinfo\"]) > 0 :\n",
    "      for i in range(len(msg[\"seatinfo\"])):\n",
    "         if msg[\"seatinfo\"][i][\"role_id\"] > 0:\n",
    "            seat_list.append(msg[\"seatinfo\"][i][\"seat_id\"])\n",
    "            role_list.append(msg[\"seatinfo\"][i][\"role_id\"])\n",
    "   talbe_player_count = len(seat_list)\n",
    "   _i = 0\n",
    "   for i in (seat_list):\n",
    "      table_players[i] = Player(i, role_list[_i], -1)\n",
    "      table_players[i].my_char = Character()\n",
    "      _i += 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "#身份展示\n",
    "def func_show_figure(jdata):\n",
    "    global table_players\n",
    "    table_players[jdata['seatid']].figure =  jdata['figure']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "#玩家设置\n",
    "def func_set_character(jdata):\n",
    "    global table_players\n",
    "    for item in jdata['character_info']:\n",
    "        table_players[item['seat_id']].character_id = item['char_id']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#更新玩家血量\n",
    "def func_update_hp(jdata):\n",
    "    if jdata['mark'] == 32: #hp上限\n",
    "        table_players[jdata['seat_id']].max_hp = jdata['hp']\n",
    "    elif jdata['mark'] == 128: #初始化血量\n",
    "        table_players[jdata['seat_id']].init_hp = jdata['hp']\n",
    "    elif jdata['mark'] == 1: #普通伤害\n",
    "        print(jdata['seat_id'], \" 收到 \", jdata['murder_seat_id'], \" 伤害类型：\",  jdata['mark'])\n",
    "    elif jdata['mark'] == 2: #火伤害\n",
    "        print(jdata['seat_id'], \" 收到 \", jdata['murder_seat_id'], \" 伤害类型：\",  jdata['mark'])\n",
    "    elif jdata['mark'] == 4: #雷伤害\n",
    "        print(jdata['seat_id'], \" 收到 \", jdata['murder_seat_id'], \" 伤害类型：\",  jdata['mark'])\n",
    "    elif jdata['mark'] == 8: #传导伤害\n",
    "        print(jdata['seat_id'], \" 收到 \", jdata['murder_seat_id'], \" 伤害类型：\",  jdata['mark'])\n",
    "    elif jdata['mark'] == 16: #流失\n",
    "        print(jdata['seat_id'], \" 收到 \", jdata['murder_seat_id'], \" 伤害类型：\",  jdata['mark'])\n",
    "    elif jdata['mark'] == 64: #1v1特殊掉血\n",
    "        print(jdata['seat_id'], \" 收到 \", jdata['murder_seat_id'], \" 伤害类型：\",  jdata['mark'])\n",
    "    return"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "class EmPosition(Enum):\n",
    "    POS_FRONT_BOTTOM        = 0        #一位置，最底下的位\n",
    "    POS_CHEAT_TIP\t\t\t= 1\n",
    "    POS_BACK_TOP            = 65280   #最后的位置，最上面的位\n",
    "    POS_RANDOM              = 65281   #随机位置\n",
    "    POS_NEEDLESS            = 65282   #无需指出\n",
    "\n",
    "#movecard \n",
    "class eZoneType(Enum):\n",
    "    ZONE_INVALID = 0\n",
    "    ZONE_CARDPILE = 1    #摸牌\n",
    "    ZONE_DISACARPILE = 2  #弃牌\n",
    "    ZONE_STACK = 3        #堆叠区域\n",
    "    ZONE_REMOVED = 4      #场?\n",
    "    ZONE_HAND = 5        #手牌\n",
    "    ZONE_EQUIP = 6        #装区\n",
    "    ZONE_JUDGE = 7        #判定\n",
    "    ZONE_SPELL = 8         #技能使用的牌的区域，属于具体spell\n",
    "    ZONE_SHUFFLE = 9\t\t#洗牌(告诉客户,洗牌了或者牌堆的数量)\n",
    "    ZONE_TEMP = 10\t\t\t#临时区域,如交换时使用,从A区域到temp区域时会触发A失去事件, 从temp到B区域会触发B区域得到卡牌事件(此时卡牌在之前区域的信息不会更新)\n",
    "    ZONE_DISCARD_BUFF = 11\t#弃牌临时区域 客户用来提示\n",
    "    ZONE_VIRTUAL = 12\t\t#虚拟区，用来存放一些特殊牌，霹雳车。这区域不属于任何色或者技\n",
    "    ZONE_LOGIC_EX = 13      #游戏逻辑额区\n",
    "    ZONE_END = 14\t\t\t#结束\n",
    "\n",
    "def func_move_card(jsdata):\n",
    "    global add_1_horse\n",
    "    global reduce_1_horse\n",
    "    global equips_list\n",
    "    global armss_list\n",
    "    if jsdata['card_count'] == 160 or jsdata['card_count'] == 0 or jsdata['src_seat'] == 255:\n",
    "        return\n",
    "    cur_seat = jsdata['src_seat']\n",
    "\n",
    "    # 仅统计手牌数量时 data可为None 其他情况下为None直接返回\n",
    "    if jsdata['from_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        table_players[jsdata['from_id']].hand_cards_count -= jsdata['card_count']\n",
    "    if jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        table_players[jsdata['to_id']].hand_cards_count += jsdata['card_count']\n",
    "\n",
    "    if jsdata['data'] == None:\n",
    "        return\n",
    "\n",
    "    #15 从摸牌堆到手牌区 \n",
    "    if jsdata['from_zone'] == eZoneType.ZONE_CARDPILE.value and jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].hand_cards.append(_c)\n",
    "    #53 从手牌区到堆叠区 \n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_HAND.value and jsdata['to_zone'] == eZoneType.ZONE_STACK.value:\n",
    "        for _c in jsdata['data']:\n",
    "            if _c in table_players[jsdata['from_id']].hand_cards:\n",
    "               table_players[jsdata['from_id']].hand_cards.remove(_c)\n",
    "               #增加到出牌的牌组\n",
    "               table_players[jsdata['from_id']].out_cards.append(_c)\n",
    "            else:\n",
    "               print(\"从堆叠区域到 53 remove error card=\", _c, jsdata['from_id'])\n",
    "    #36 从堆叠区域到装备区 \n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_STACK.value and jsdata['to_zone'] == eZoneType.ZONE_EQUIP.value:\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].zb_cards.append(_c)\n",
    "            #如果是+1马\n",
    "            if _c in add_1_horse:\n",
    "                table_players[jsdata['to_id']].add_horse = _c\n",
    "            elif _c in reduce_1_horse:\n",
    "                table_players[jsdata['to_id']].reduce_horse = _c\n",
    "            elif _c in equips_list:\n",
    "                table_players[jsdata['to_id']].equips = _c\n",
    "            elif _c in armss_list:\n",
    "                table_players[jsdata['to_id']].arms = _c\n",
    "            else:\n",
    "                print(\" 装备错误\")\n",
    "    #55 从手牌区域到手牌 (顺手牵羊)\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_HAND.value and jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        for _c in jsdata['data']:\n",
    "            #标添加手\n",
    "            table_players[jsdata['to_id']].hand_cards.append(_c)\n",
    "            #从玩家删除手\n",
    "            if _c in table_players[jsdata['from_id']].hand_cards:\n",
    "                table_players[jsdata['from_id']].hand_cards.remove(_c)\n",
    "            else:\n",
    "                print(\"55 从手牌区域到手牌 remove error\", table_players[jsdata['from_id']].hand_cards , _c)\n",
    "    #32 从堆叠区域到弃牌区域 属于出牌 \n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_STACK.value and jsdata['to_zone'] == eZoneType.ZONE_DISACARPILE.value:\n",
    "        print(\"从堆叠区域到弃牌区域 \", jsdata['data'])\n",
    "    #13 从摸牌堆到堆叠区 从牌堆中摸出牌作为判定牌\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_CARDPILE.value and jsdata['to_zone'] == eZoneType.ZONE_STACK.value:\n",
    "        print(\"13 从摸牌堆到堆叠区 \", jsdata['data'])\n",
    "     #35 从堆叠区域到手牌区域 判定牌生效后，你就可以使用天妒技能获得那张使判定牌生效的牌。例如乐不思蜀\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_STACK.value and jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].hand_cards.append(_c)\n",
    "    #52 从手牌区到弃牌区 \n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_HAND.value and jsdata['to_zone'] == eZoneType.ZONE_DISACARPILE.value:\n",
    "        temp_give = []\n",
    "        for _c in jsdata['data']:\n",
    "            temp_give.append(_c)\n",
    "        table_players[jsdata['from_id']].giveup_cards.append(temp_give)   \n",
    "    #37 从堆叠区域到判定\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_STACK.value and jsdata['to_zone'] == eZoneType.ZONE_JUDGE.value:\n",
    "        print(\"从堆叠区域到判定 \", jsdata['data'])\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].decide_cards.append(_c)\n",
    "        \n",
    "    #18 从摸牌区域到技能使用的牌的区域 属于具体spell 五谷丰登\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_CARDPILE.value and jsdata['to_zone'] == eZoneType.ZONE_SPELL.value:\n",
    "        print(\"从摸牌区域到技能使用的牌的区域 属于具体spell \", jsdata['data'], \" spell \", jsdata['spell_id'])\n",
    "    #85 从技能使用的牌的区域，属于具体spell 到手牌区\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_SPELL.value and jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].hand_cards.append(_c)\n",
    "    #72 判定区到弃牌\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_JUDGE.value and jsdata['to_zone'] == eZoneType.ZONE_DISACARPILE.value:\n",
    "        print(\"72 判定区到弃牌 \", jsdata['data'])\n",
    "        for _c in jsdata['data']:\n",
    "            if _c in table_players[jsdata['from_id']].decide_cards:\n",
    "                table_players[jsdata['from_id']].decide_cards.remove(_c)\n",
    "    #62 装区到弃牌区\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_EQUIP.value and jsdata['to_zone'] == eZoneType.ZONE_DISACARPILE.value:\n",
    "        for _c in jsdata['data']:\n",
    "            if _c in table_players[jsdata['from_id']].zb_cards:\n",
    "                table_players[jsdata['from_id']].zb_cards.remove(_c)\n",
    "                #如果是+1马\n",
    "                if _c in add_1_horse:\n",
    "                    table_players[jsdata['from_id']].add_horse = -1\n",
    "                elif _c in reduce_1_horse:\n",
    "                    table_players[jsdata['from_id']].reduce_horse = -1\n",
    "                elif _c in equips_list:\n",
    "                    table_players[jsdata['from_id']].equips = -1\n",
    "                elif _c in armss_list:\n",
    "                    table_players[jsdata['from_id']].arms = -1\n",
    "                else:\n",
    "                    print(\" 装备错误\")\n",
    "            else:\n",
    "                print(\"62 装区到弃牌区 error 装区没这种牌\")\n",
    "    #65 装区到手牌区\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_EQUIP.value and jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].hand_cards.append(_c)\n",
    "            if _c in table_players[jsdata['from_id']].zb_cards:\n",
    "                table_players[jsdata['from_id']].zb_cards.remove(_c)\n",
    "                #如果是+1马\n",
    "                if _c in add_1_horse:\n",
    "                    table_players[jsdata['from_id']].add_horse = -1\n",
    "                elif _c in reduce_1_horse:\n",
    "                    table_players[jsdata['from_id']].reduce_horse = -1\n",
    "                elif _c in equips_list:\n",
    "                    table_players[jsdata['from_id']].equips = -1\n",
    "                elif _c in armss_list:\n",
    "                    table_players[jsdata['from_id']].arms = -1\n",
    "                else:\n",
    "                    print(\" 装备错误\")\n",
    "            else:\n",
    "                print(\"62 装区到弃牌区 error 装区没这种牌\")\n",
    "    #82 从技能使用的牌的区域，属于具体spell 到手牌区到弃牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_SPELL.value and jsdata['to_zone'] == eZoneType.ZONE_DISACARPILE.value:\n",
    "        print(\"82 从技能使用的牌的区域，属于具体spell 到手牌区到弃牌堆 \", jsdata['data'])\n",
    "    #33 从堆叠区 到堆叠区\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_STACK.value and jsdata['to_zone'] == eZoneType.ZONE_STACK.value:\n",
    "        print(\"33 从堆叠区 到堆叠区 \", jsdata['data'])\n",
    "    #61 从区 到摸牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_EQUIP.value and jsdata['to_zone'] == eZoneType.ZONE_CARDPILE.value:\n",
    "        for _c in jsdata['data']:\n",
    "            if _c in table_players[jsdata['from_id']].zb_cards:\n",
    "                table_players[jsdata['from_id']].zb_cards.remove(_c)\n",
    "                #如果是+1马\n",
    "                if _c in add_1_horse:\n",
    "                    table_players[jsdata['from_id']].add_horse = -1\n",
    "                elif _c in reduce_1_horse:\n",
    "                    table_players[jsdata['from_id']].reduce_horse = -1\n",
    "                elif _c in equips_list:\n",
    "                    table_players[jsdata['from_id']].equips = -1\n",
    "                elif _c in armss_list:\n",
    "                    table_players[jsdata['from_id']].arms = -1\n",
    "                else:\n",
    "                    print(\" 装备错误\")\n",
    "            else:\n",
    "                print(\"62 装区到弃牌区 error 装区没这种牌\")\n",
    "    #31 从堆叠区 到摸牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_STACK.value and jsdata['to_zone'] == eZoneType.ZONE_CARDPILE.value:\n",
    "        print(\"31 从堆叠区 到摸牌堆 \", jsdata['data'])\n",
    "    #51 从手 到摸牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_HAND.value and jsdata['to_zone'] == eZoneType.ZONE_CARDPILE.value:\n",
    "        for _c in jsdata['data']:\n",
    "            #从玩家删除手\n",
    "            if _c in table_players[jsdata['from_id']].hand_cards:\n",
    "                table_players[jsdata['from_id']].hand_cards.remove(_c)\n",
    "            else:\n",
    "                print(\"51 从手牌区 到摸牌堆  游戏开始免费换 remove error\", table_players[jsdata['from_id']].hand_cards , _c)\n",
    "    #58 从手牌区 到技能使用的牌的区域，属于具体spell 惠民\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_HAND.value and jsdata['to_zone'] == eZoneType.ZONE_SPELL.value:\n",
    "        for _c in jsdata['data']:\n",
    "            #从玩家删除手\n",
    "            if _c in table_players[jsdata['from_id']].hand_cards:\n",
    "                table_players[jsdata['from_id']].hand_cards.remove(_c)\n",
    "            else:\n",
    "                print(\"58 从手牌区 到技能使用的牌的区域 remove error\", table_players[jsdata['from_id']].hand_cards , _c)\n",
    "    #24 从弃牌堆到场\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_DISACARPILE.value and jsdata['to_zone'] == eZoneType.ZONE_REMOVED.value:\n",
    "        print(\"24 从弃牌堆到场 \", jsdata['data'])\n",
    "    #43 从场外堆到堆叠区\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_REMOVED.value and jsdata['to_zone'] == eZoneType.ZONE_STACK.value:\n",
    "        print(\"43 从场外堆到堆叠区\", jsdata['data'])\n",
    "    #22 从弃牌堆到弃牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_REMOVED.value and jsdata['to_zone'] == eZoneType.ZONE_REMOVED.value:\n",
    "        print(\"22 从弃牌堆堆到从弃牌堆\", jsdata['data'])\n",
    "    #25 从弃牌堆到手牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_REMOVED.value and jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].hand_cards.append(_c)\n",
    "    #63 从堆到堆叠区\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_EQUIP.value and jsdata['to_zone'] == eZoneType.ZONE_STACK.value:\n",
    "        for _c in jsdata['data']:\n",
    "            if _c in table_players[jsdata['from_id']].zb_cards:\n",
    "                table_players[jsdata['from_id']].zb_cards.remove(_c)\n",
    "                #如果是+1马\n",
    "                if _c in add_1_horse:\n",
    "                    table_players[jsdata['from_id']].add_horse = -1\n",
    "                elif _c in reduce_1_horse:\n",
    "                    table_players[jsdata['from_id']].reduce_horse = -1\n",
    "                elif _c in equips_list:\n",
    "                    table_players[jsdata['from_id']].equips = -1\n",
    "                elif _c in armss_list:\n",
    "                    table_players[jsdata['from_id']].arms = -1\n",
    "                else:\n",
    "                    print(\" 装备错误\")\n",
    "            else:\n",
    "                print(\"63 从堆到从堆叠区域 error 装区没这种牌\")\n",
    "    #510 从手牌堆到临时区,如交换时使用\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_HAND.value and jsdata['to_zone'] == eZoneType.ZONE_TEMP.value:\n",
    "        for _c in jsdata['data']:\n",
    "            #从玩家删除手\n",
    "            if _c in table_players[jsdata['from_id']].hand_cards:\n",
    "                table_players[jsdata['from_id']].hand_cards.remove(_c)\n",
    "            else:\n",
    "                print(\"510 从手牌堆到临时区,如交换时使用 remove error\", table_players[jsdata['from_id']].hand_cards , _c)\n",
    "    #105 从临时区,如交换时使用到手牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_TEMP.value and jsdata['to_zone'] == eZoneType.ZONE_HAND.value:\n",
    "        for _c in jsdata['data']:\n",
    "            #从玩家删除手\n",
    "            table_players[jsdata['to_id']].hand_cards.append(_c)\n",
    "    #21 从弃牌堆到摸牌堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_DISACARPILE.value and jsdata['to_zone'] == eZoneType.ZONE_CARDPILE.value:\n",
    "        print(\"21 从弃牌堆到摸牌堆 \",jsdata['data'])\n",
    "    #77 从判定堆到判定堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_JUDGE.value and jsdata['to_zone'] == eZoneType.ZONE_JUDGE.value:\n",
    "        print(\"77 从判定堆到判定堆  例如闪电\",jsdata['data'])\n",
    "        for _c in jsdata['data']:\n",
    "            table_players[jsdata['to_id']].decide_cards.append(_c)\n",
    "            if _c in table_players[jsdata['from_id']].decide_cards:\n",
    "                table_players[jsdata['from_id']].decide_cards.remove(_c)\n",
    "    #34 从堆叠区域堆到场外堆\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_STACK.value and jsdata['to_zone'] == eZoneType.ZONE_REMOVED.value:\n",
    "        print(\"34 从堆叠区域堆到场外堆 \",jsdata['data'])\n",
    "    #66 从装备区域堆到装备区\n",
    "    elif jsdata['from_zone'] == eZoneType.ZONE_EQUIP.value and jsdata['to_zone'] == eZoneType.ZONE_EQUIP.value:\n",
    "        for _c in jsdata['data']:\n",
    "            #从玩家删除手\n",
    "            table_players[jsdata['to_id']].zb_cards.append(_c)\n",
    "            #如果是+1马\n",
    "            if _c in add_1_horse:\n",
    "                table_players[jsdata['to_id']].add_horse = _c\n",
    "            elif _c in reduce_1_horse:\n",
    "                table_players[jsdata['to_id']].reduce_horse = _c\n",
    "            elif _c in equips_list:\n",
    "                table_players[jsdata['to_id']].equips = _c\n",
    "            elif _c in armss_list:\n",
    "                table_players[jsdata['to_id']].arms = _c\n",
    "            else:\n",
    "                print(\" 装备错误\")\n",
    "            if _c in table_players[jsdata['from_id']].zb_cards:\n",
    "                table_players[jsdata['from_id']].zb_cards.remove(_c)\n",
    "                #如果是+1马\n",
    "                if _c in add_1_horse:\n",
    "                    table_players[jsdata['from_id']].add_horse = -1\n",
    "                elif _c in reduce_1_horse:\n",
    "                    table_players[jsdata['from_id']].reduce_horse = -1\n",
    "                elif _c in equips_list:\n",
    "                    table_players[jsdata['from_id']].equips = -1\n",
    "                elif _c in armss_list:\n",
    "                    table_players[jsdata['from_id']].arms = -1\n",
    "                else:\n",
    "                    print(\" 装备错误\")\n",
    "            else:\n",
    "                print(\"510 从手牌堆到临时区,如交换时使用 remove error\", table_players[jsdata['from_id']].zb_cards , _c)\n",
    "    else:\n",
    "        print(\"move card error \", jsdata['from_zone'], jsdata['to_zone']) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "#使用手牌 table_id, patrol_id, phase_id, round_id, cur_play_seat, sub_json_data\n",
    "def func_use_card(tableid, patrolid, phaseid, roundid, curplayseat, jdata):\n",
    "    _info_str = ''\n",
    "    #table\n",
    "    _info_str = contanctStr(_info_str, tableid)\n",
    "    #patrolid\n",
    "    _info_str = contanctStr(_info_str, patrolid)\n",
    "    #roundid\n",
    "    _info_str = contanctStr(_info_str, roundid)\n",
    "    #curplayseat\n",
    "    _info_str = contanctStr(_info_str, curplayseat)\n",
    "    #player_info\n",
    "    for i in range(talbe_player_count):\n",
    "        #boold\n",
    "        _info_str = contanctStr(_info_str, table_players[jdata['seat_id']].init_hp)\n",
    "        #player1_cards\n",
    "        _info_str = ansyiceHandcards(_info_str, table_players[jdata['seat_id']].hand_cards)\n",
    "        #player1_sum\n",
    "        _info_str = contanctStr(_info_str, table_players[jdata['seat_id']].hand_cards_count)\n",
    "        #player1_arms\n",
    "        _info_str = contanctStr(_info_str, table_players[jdata['seat_id']].arms)\n",
    "        #player1_armor\n",
    "        _info_str = contanctStr(_info_str, table_players[jdata['seat_id']].equips)\n",
    "        #player1_add_horse\n",
    "        _info_str = contanctStr(_info_str, table_players[jdata['seat_id']].add_horse)\n",
    "        #player1_reduce_horse\n",
    "        _info_str = contanctStr(_info_str, table_players[jdata['seat_id']].reduce_horse)\n",
    "        #player1_lbss_state\n",
    "        _info_str = contanctStr(_info_str, judge_have_lbss(table_players[jdata['seat_id']].decide_cards))\n",
    "        #player1_flash_state\n",
    "        _info_str = contanctStr(_info_str, judge_have_flash(table_players[jdata['seat_id']].decide_cards))\n",
    "        #player1_blcd_state\n",
    "        _info_str = contanctStr(_info_str, judge_have_blcd(table_players[jdata['seat_id']].decide_cards))\n",
    "        #player1_jiu_state 此处需要特殊处理\n",
    "        _info_str = contanctStr(_info_str, judge_have_blcd(table_players[jdata['seat_id']].decide_cards))\n",
    "        #player1_tslh_state \n",
    "        _info_str = contanctStr(_info_str, judge_have_tslh(table_players[jdata['seat_id']].decide_cards))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "#游戏巡数\n",
    "def func_turn_info(jdata):\n",
    "    print(\"当前游戏巡数为：\",jdata['turn'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [],
   "source": [
    "#保存数据到csv\n",
    "def save2csv(filename, idata):\n",
    "    file_out = open(\"save_data./\"+filename, 'a+', encoding='UTF-8')  # create file\n",
    "    file_out.write(idata+\"\\n\")\n",
    "    file_out.close()\n",
    "\n",
    "#字符串联\n",
    "def contanctStr(basestr, addstr):\n",
    "    basestr = basestr + \",\"+str(addstr)\n",
    "    return basestr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "#处理table\n",
    "table_title = 'table_id,players_sum,game_mode,player_online_info,player_1_role,player_1_identity,player_1_hero_id,player_1_A_boold,player_1_ending,player_2_role,player_2_identity,player_2_hero_id,player_2_A_boold,player_2_ending,player_3_role,player_3_identity,player_3_hero_id,player_3_A_boold,player_3_ending,player_4_role,player_4_identity,player_4_hero_id,player_4_A_boold,player_4_ending,player_5_role,player_5_identity,player_5_hero_id,player_5_A_boold,player_5_ending,player_6_role,player_6_identity,player_6_hero_id,player_6_A_boold,player_6_ending,player_7_role,player_7_identity,player_7_hero_id,player_7_A_boold,player_7_ending,player_8_role,player_8_identity,player_8_hero_id,player_8_A_boold,player_8_ending'\n",
    "table_name = 'table_info.csv'\n",
    "save2csv(table_name, table_title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [],
   "source": [
    "#保存table表\n",
    "def save_table_info(roundid):\n",
    "    _info_str = str(roundid) #roundid\n",
    "    _info_str = contanctStr(_info_str, talbe_player_count) #players_sum\n",
    "    _info_str = contanctStr(_info_str, table_game_mode) #game_mode\n",
    "    _info = ''\n",
    "    for i in range(talbe_player_count):\n",
    "        if table_players[i]:\n",
    "            _info  = _info + '1|'\n",
    "        else:\n",
    "            _info  = _info + '0|'\n",
    "    _info_str = contanctStr(_info_str, _info) #player_online_info\n",
    "\n",
    "    #基本信息\n",
    "    for i in range(talbe_player_count):\n",
    "        if table_players[i]:\n",
    "            _info_str = contanctStr(_info_str, table_players[i].role_id)\n",
    "            _info_str = contanctStr(_info_str, table_players[i].figure)\n",
    "            _info_str = contanctStr(_info_str, table_players[i].character_id)\n",
    "            _info_str = contanctStr(_info_str, table_players[i].init_hp)\n",
    "            _info_str = contanctStr(_info_str, table_players[i].result)\n",
    "        else:\n",
    "            _info_str = contanctStr(_info_str, 0)\n",
    "            _info_str = contanctStr(_info_str, 0)\n",
    "            _info_str = contanctStr(_info_str, 0)\n",
    "            _info_str = contanctStr(_info_str, 0)\n",
    "            _info_str = contanctStr(_info_str, 0)\n",
    "    #result 信息\n",
    "    save2csv(table_name, _info_str)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [],
   "source": [
    "#游戏结束\n",
    "def func_game_over(roundid, jdata):\n",
    "    palyercount = jdata[\"player_count\"]\n",
    "    str_result=[\"赢了\",\"输了\"]\n",
    "    str_figure=[\"\",\"主\",\"忠\",\"反\",\"内\",\"身份不明\",\"身份不合法\"]\n",
    "    for i in range(palyercount):\n",
    "        seatid = jdata[\"game_result\"][i][\"seat_id\"]\n",
    "        result = jdata[\"game_result\"][i][\"result\"]\n",
    "        figure = jdata[\"game_result\"][i][\"figure\"]\n",
    "        name = table_players[seatid].my_name\n",
    "        table_players[seatid].result = result\n",
    "        if result > 0:\n",
    "            result = 1\n",
    "        print(name, str_result[result], \"身份为:\",str_figure[figure])\n",
    "    save_table_info(roundid)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f:\\MyGitee\\threeKilled\\jsonParse\\record_sel.zip\n",
      "record_sel/000018783ea7752ba1b7299903017147.sgs.json\n",
      "0    record_sel/000018783ea7752ba1b7299903017147.sgs.json\n",
      "init player\n",
      "init player\n",
      "init player\n",
      "init player\n",
      "当前游戏巡数为： 1\n",
      "从堆叠区域到 53 remove error card= 79 3\n",
      "从堆叠区域到 53 remove error card= 64 1\n",
      "从堆叠区域到弃牌区域  [64]\n",
      "从堆叠区域到弃牌区域  [79]\n",
      "从堆叠区域到 53 remove error card= 55 3\n",
      "0  收到  3  伤害类型： 1\n",
      "从堆叠区域到弃牌区域  [55]\n",
      "从堆叠区域到 53 remove error card= 144 3\n",
      "从堆叠区域到判定  [144]\n",
      "从堆叠区域到 53 remove error card= 121 1\n",
      "从堆叠区域到 53 remove error card= 147 2\n",
      "从堆叠区域到弃牌区域  [147]\n",
      "从堆叠区域到弃牌区域  [121]\n",
      "13 从摸牌堆到堆叠区  [84]\n",
      "从堆叠区域到弃牌区域  [84]\n",
      "72 判定区到弃牌  [144]\n",
      "从堆叠区域到弃牌区域  [4]\n",
      "从堆叠区域到弃牌区域  [33]\n",
      "2  收到  0  伤害类型： 1\n",
      "从堆叠区域到弃牌区域  [100]\n",
      "从堆叠区域到 53 remove error card= 80 1\n",
      "从堆叠区域到 53 remove error card= 158 1\n",
      "从堆叠区域到弃牌区域  [158]\n",
      "从堆叠区域到 53 remove error card= 91 1\n",
      "从堆叠区域到 53 remove error card= 73 2\n",
      "从堆叠区域到弃牌区域  [73]\n",
      "3  收到  1  伤害类型： 1\n",
      "0  收到  1  伤害类型： 1\n",
      "从堆叠区域到弃牌区域  [91]\n",
      "从堆叠区域到 53 remove error card= 37 1\n",
      "从堆叠区域到弃牌区域  [37]\n",
      "从堆叠区域到 53 remove error card= 27 1\n",
      "从堆叠区域到 53 remove error card= 24 2\n",
      "从堆叠区域到弃牌区域  [24]\n",
      "从堆叠区域到 53 remove error card= 22 3\n",
      "从堆叠区域到弃牌区域  [22]\n",
      "从堆叠区域到弃牌区域  [41]\n",
      "从堆叠区域到弃牌区域  [27]\n",
      "从堆叠区域到 53 remove error card= 50 1\n",
      "2  收到  1  伤害类型： 1\n",
      "从堆叠区域到弃牌区域  [50]\n",
      "当前游戏巡数为： 2\n",
      "从堆叠区域到 53 remove error card= 3 3\n",
      "从堆叠区域到弃牌区域  [3]\n",
      "从堆叠区域到 53 remove error card= 72 3\n",
      "0  收到  3  伤害类型： 1\n",
      "从堆叠区域到 53 remove error card= 26 1\n",
      "从堆叠区域到弃牌区域  [26]\n",
      "从堆叠区域到弃牌区域  [72]\n",
      "从堆叠区域到 53 remove error card= 92 3\n",
      "从堆叠区域到 53 remove error card= 65 3\n",
      "从堆叠区域到 53 remove error card= 21 1\n",
      "从堆叠区域到弃牌区域  [21]\n",
      "从堆叠区域到弃牌区域  [92, 65]\n",
      "从堆叠区域到弃牌区域  [47]\n",
      "从堆叠区域到 53 remove error card= 68 1\n",
      "从堆叠区域到弃牌区域  [68]\n",
      "从堆叠区域到 53 remove error card= 104 1\n",
      "从堆叠区域到 53 remove error card= 67 1\n",
      "从堆叠区域到 53 remove error card= 36 1\n",
      "3  收到  1  伤害类型： 1\n",
      "从堆叠区域到弃牌区域  [36]\n",
      "当前游戏巡数为： 3\n",
      "从堆叠区域到 53 remove error card= 42 3\n",
      "从堆叠区域到弃牌区域  [42]\n",
      "从堆叠区域到 53 remove error card= 87 3\n",
      "从堆叠区域到 53 remove error card= 127 0\n",
      "从堆叠区域到弃牌区域  [127]\n",
      "从堆叠区域到弃牌区域  [87]\n",
      "从摸牌区域到技能使用的牌的区域 属于具体spell  [106, 118, 53]  spell  6\n",
      "从堆叠区域到 53 remove error card= 109 1\n",
      "从堆叠区域到弃牌区域  [109]\n",
      "82 从技能使用的牌的区域，属于具体spell 到手牌区到弃牌堆  [106]\n",
      "从堆叠区域到弃牌区域  [30]\n",
      "3  收到  0  伤害类型： 2\n",
      " 赢了 身份为: 忠\n",
      " 赢了 身份为: 忠\n",
      " 输了 身份为: 反\n",
      " 输了 身份为: 反\n"
     ]
    }
   ],
   "source": [
    "# def read_json_func(filepath):\n",
    "#     return json.load(open(filepath,'r',encoding=\"utf-8\"))\n",
    "\n",
    "#从压缩文件中读取json文件\n",
    "print(os.path.join(os.getcwd(), 'record_sel.zip'))\n",
    "zipFile = zipfile.ZipFile(os.path.join(os.getcwd(), 'record_sel.zip'))\n",
    "is_find = False\n",
    "table_id = 0\n",
    "for file in zipFile.namelist():\n",
    "    print(file)\n",
    "    # json_data = read_json_func(file) \n",
    "    json_data = json.load(zipFile.open(file,'r'))\n",
    "    talbe_player_count = 0\n",
    "    reset_player_info()\n",
    "    if json_data[0]['model'] not in mode_2V2:\n",
    "        continue\n",
    "    print(table_id, \"  \", file)\n",
    "    patrol_id = 0\n",
    "    round_id = 0\n",
    "    phase_id = 0\n",
    "    cur_play_seat = 0\n",
    "    for j_data in json_data:\n",
    "        sub_json_data = j_data\n",
    "        if j_data[\"id\"]  == 21208:\n",
    "            func_userseat_ntf(sub_json_data)\n",
    "        elif j_data[\"id\"] == 21223:\n",
    "            func_show_figure(sub_json_data)\n",
    "        elif j_data[\"id\"] == 21216:\n",
    "            func_update_hp(sub_json_data)\n",
    "        elif j_data[\"id\"] == 21227:\n",
    "            func_set_character(sub_json_data)\n",
    "        elif j_data[\"id\"] == 21296:\n",
    "            func_turn_info(sub_json_data)\n",
    "        elif j_data[\"id\"] == 21228:\n",
    "            func_game_over(table_id, sub_json_data)\n",
    "        elif j_data[\"id\"]  == 21209: #MOVE_CARD\n",
    "            func_move_card(sub_json_data)\n",
    "        elif j_data[\"id\"]  == 21210: #USE_CARD\n",
    "            if j_data['seat_id'] == cur_play_seat:\n",
    "                func_use_card(table_id, patrol_id, phase_id, round_id, cur_play_seat, sub_json_data)\n",
    "            #else:\n",
    "                #func_use_card_other(table_id, patrol_id, phase_id, round_id, cur_play_seat, sub_json_data)\n",
    "            round_id += 1\n",
    "        elif j_data[\"id\"]  == 21213: #游戏阶段\n",
    "            phase_id = j_data[\"phase_id\"]\n",
    "            if j_data[\"phase_id\"] == 0:\n",
    "                patrol_id += 1\n",
    "                round_id = 0\n",
    "            #保存当前回合的seat\n",
    "            cur_play_seat = j_data[\"cur_seatid\"]\n",
    "    round_id += 1\n",
    "    break"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "2\n",
      "3\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for i in range(4):\n",
    "    print(table_players[i].figure)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "eed15c5e4cc9f5aab9395fba058aefe03ad91a46554f58df00d87578c2f68b4d"
  },
  "kernelspec": {
   "display_name": "Python 3.7.0 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
